// 商城订单处理方法
import logger from '@common/logger';
import { SHOP_ORDER_AFTER_SALE_TYPE } from '@constants/shop';
import { SHOP_ORDER_STATUS, AFTER_ORDER_STATUS } from '@constants/shopOrderStatus';

export const getShopOrderTipInfo = (orderDetail) => {
    logger.info('商城订单状态处理--订单详情', orderDetail);
    const { status, delivery_type, refund_flag } = orderDetail;
    let text = '订单状态异常';
    let tip = '订单状态异常，请刷新后尝试';
    let iconType = '';
    let isHavePay = false;
    let isHaveCancel = false;
    let isHaveAfterSale = false;
    let isHaveActionBar = false;
    let isHaveExpressInfo = false;
    let isHavePickUpInfo = false;
    let isHavePickUpCode = false;
    let isHaveReceivi = false;
    let isClosed = false;
    let isPickUp = delivery_type === 0;
    let isDayExpress = delivery_type === 1;
    let isExpress = delivery_type === 2;
    switch (status) {
    case SHOP_ORDER_STATUS.ORDER_NEED_PAY:
        text = '待付款';
        tip = '请在10分钟内完成付款';
        isHaveCancel = true;
        iconType = 'pay';
        isHavePay = true;
        isHaveActionBar = true;
        break;
    case SHOP_ORDER_STATUS.ORDER_NEED_STOCK_UP:
        text = '待备货';
        tip = '商家正在备货中，请等待备货完成';
        isHaveCancel = true;
        iconType = 'pack';
        break;
    case SHOP_ORDER_STATUS.ORDER_NEED_PICK_UP:
        text = '待自提';
        tip = '商品已备货完成，请出示取货码自提';
        iconType = 'pickup';
        isHavePickUpInfo = true;
        isHaveActionBar = true;
        isHavePickUpCode = true;
        isHaveReceivi = true;
        break;
    case SHOP_ORDER_STATUS.ORDER_NEED_DELIVERY:
        text = '待配送';
        tip = '商家正在备货中，请等待发货';
        isHaveCancel = true;
        iconType = 'pack';
        break;
    case SHOP_ORDER_STATUS.ORDER_NEED_SIGN_IN:
        text = '待签收';
        tip = '商家已发货，15天后将自动签收';
        iconType = 'package';
        isHaveReceivi = true;
        isHavePickUpInfo = true;
        isHaveActionBar = true;
        isHaveAfterSale = true;
        isHaveExpressInfo = true;
        break;
    case SHOP_ORDER_STATUS.ORDER_COMPLETE:
        text = '已完成';
        tip = '感谢您的支持，期待下次光临';
        iconType = 'complete';
        isHaveAfterSale = true;
        isHaveExpressInfo = true;
        break;
    case SHOP_ORDER_STATUS.ORDER_CLOSE:
        text = '订单已关闭';
        tip = '交易取消，已关闭订单';
        iconType = 'close';
        isClosed = true;
        break;
    }
    return {
        text,
        tip,
        iconType,
        isHavePay,
        isHaveCancel: refund_flag === 1 ? false : isHaveCancel,
        isHaveAfterSale,
        isHaveActionBar,
        isHaveExpressInfo,
        isHavePickUpInfo,
        isHavePickUpCode,
        isHaveReceivi,
        isPickUp,
        isDayExpress,
        isExpress,
        isClosed,
    };
};

export const getShopAfterSaleOrderTipInfo = (orderDetail) => {
    logger.info('商城售后订单状态处理--订单详情', orderDetail);
    const { status, type } = orderDetail;
    let text = '订单状态异常';
    let tip = '订单状态异常，请刷新后尝试';
    let isHaveCancel = false;
    let isHaveExpress = false;
    let isShowExpress = false;
    switch (status) {
    case AFTER_ORDER_STATUS.APPLYING:
        text = '退款申请中';
        tip = '商家正在审核中，请耐心等待';
        isHaveCancel = true;
        break;
    case AFTER_ORDER_STATUS.SOTRE_REFUND:
        text = '商家拒绝';
        tip = '如有疑问请联系人工客服';
        break;
    case AFTER_ORDER_STATUS.WAITE_SEND_BACK:
        text = '商家同意退货，请寄回商品';
        tip = '请填写退货物流单号';
        isHaveCancel = true;
        isHaveExpress = true;
        break;
    case AFTER_ORDER_STATUS.WAITE_PUT_STORAGE:
        text = '退货品已寄出，等待商家签收';
        tip = '商品运输中，请耐心等待';
        isHaveExpress = true;
        isShowExpress = true;
        break;
    case AFTER_ORDER_STATUS.SUCCESS:
        text = '退款成功';
        tip = '售后服务已完成，如有疑问请联系客服';
        break;
    case AFTER_ORDER_STATUS.FAIL:
        text = '退款失败';
        tip = '售后服务已完成，如有疑问请联系客服';
        break;
    case AFTER_ORDER_STATUS.CLOSE:
        text = '退款关闭';
        tip = '您已取消退款申请，退款已关闭';
        break;
    default:
        text = '未知售后状态';
        tip = '刷新页面获取售后信息';
        break;
    }
    return {
        text,
        tip,
        isHaveCancel,
        isHaveExpress,
        isShowExpress,
    };
};
